package com.aisino.encrypt.algorithm;

import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.digest.Digester;

/**
 * @author wangl
 * @date 2021-09-27 14:44
 * 国密SM3杂凑（摘要）算法
 */
public class SM3Util {

    private static byte[] saltByte = {48, 89, 48, 19, 6, 7, 42, -122, 72, -50, 61, 2, 1, 6, 8, 42, -127, 28, -49, 85, 1, -126, 45, 3, 66, 0, 4, -33, -7, -80, 16, 13, 45, 65, -93, 42, 26, 16, -24, 120, 68, 39, 43, -8, -10, -91, 90, -40, -95, -107, 77, -72, -75, 71, 83, -70, -37, -100, 71, -49, -88, -92, 126, -99, -113, 10, -118, -33, 76, 18, 89, 1, -128, 36, -92, 106, -89, -89, -18, 17, -122, -66, -34, 94, 96, 64, -96, 37, -69, -117, 35} ;

    public static String encrypt(String msg) {
        Digester digester = DigestUtil.digester("sm3");
        // 加盐
        digester.setSalt(saltByte);
        return digester.digestHex(msg);
    }

    public static void main(String[] args) {
        System.out.println(encrypt("1234567890123456789012"));
    }
}
